import storage from "@/utils/storage";
import {
  createRouter,
  createWebHashHistory,
  createWebHistory,
} from "vue-router";
import { RouteRecordRaw } from "vue-router";

const routes: RouteRecordRaw[] = [
  {
    name: "home",
    path: "/",
    redirect: "/index",
    meta: {
      title: "推荐",
    },
    component: () => import("../views/layout/layout.vue"),
    children: [
      {
        name: "推荐",
        path: "/index",
        component: () => import("../views/home/home.vue"),
        meta: {
          title: "推荐",
        },
      },
      {
        name: "音乐",
        path: "/song/:id",
        component: () => import("../views/song/song.vue"),
        meta: {
          title: "音乐",
        },
      },
      {
        name: "排行榜",
        path: "/rank",
        component: () => import("../views/rank/rank.vue"),
        meta: {
          title: "排行榜",
        },
      },
      {
        name: "搜索",
        path: "/search",
        component: () => import("../views/search/search.vue"),
        meta: {
          title: "搜索",
        },
      },
      {
        path: "/:pathMatch(.*)*",
        name: "404",
        meta: {
          title: "404",
        },
        component: () => import("@/views/login/login.vue"),
      },
    ],
  },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
});

router.beforeEach((to, from) => {
  // 更改网页标题
  document.title = to.meta.title + "";
});

export default router;
